package com.aitaoxue.palx.db.course;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;

public class CourseMaster extends AbstractDaoMaster {
	public static final int SCHEMA_VERSION = 1;

	public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
		CourseDao.createTable(db, ifNotExists);
		CourseTypeDao.createTable(db, ifNotExists);
	}

	public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
		CourseDao.dropTable(db, ifExists);
		CourseTypeDao.dropTable(db, ifExists);
	}

	public CourseMaster(SQLiteDatabase db, int schemaVersion) {
		super(db, schemaVersion);
		// TODO Auto-generated constructor stub
	}

	public static abstract class OpenHelper extends SQLiteOpenHelper {
		public OpenHelper(Context context, CursorFactory factory) {
			super(context, "course", factory, SCHEMA_VERSION);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			createAllTables(db, false);
		}
	}

	public static class DevOpenHelper extends OpenHelper {

		public DevOpenHelper(Context context, CursorFactory factory) {
			super(context, factory);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			dropAllTables(db, true);
			onCreate(db);
		}

	}

	@Override
	public DaoSession newSession() {
		return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
	}

	@Override
	public DaoSession newSession(IdentityScopeType type) {
		return new DaoSession(db, type, daoConfigMap);
	}

	public CourseMaster(SQLiteDatabase db) {
		super(db, SCHEMA_VERSION);
		registerDaoClass(CourseDao.class);
		registerDaoClass(CourseTypeDao.class);
	}
}
